package models

type Types struct {
	BaseModel
	Name        string `json:"name" gorm:"not null;"`        //车膜类型,
	Thickness   string `json:"thickness" gorm:"not null;"`   //厚度
	Place       string `json:"place" gorm:"not null;"`       //产地
	Type        string `json:"type" gorm:"not null;"`        //类型
	Type2       string `json:"type2" gorm:"not null;"`       //类型2
	Brand       string `json:"brand" gorm:"not null;"`       //品牌
	QualityTime string `json:"qualityTime" gorm:"not null;"` //质保时间
}

func (u *Types) CreateTable() {
	err := DB.AutoMigrate(&Types{})
	if err != nil {
		panic("创建类型表失败:" + err.Error())
	}
}

func (u *Types) Add() error {
	return DB.Create(u).Error
}

func (c *Types) Find() ([]Types, error) {
	var types []Types
	result := DB.Find(&types)
	return types, result.Error
}
func (c *Types) FindByPage(query map[string]int) ([]Types, int64, error) {
	var q []Types
	var total int64
	DB.Model(&Types{}).Where(c).Count(&total)
	result := DB.Limit(query["Limit"]).Offset(query["Offset"]).Find(&q)
	return q, total, result.Error
}

func (c *Types) Update(newDate interface{}) error {
	return DB.Model(&Types{}).Where(c).Updates(newDate).Error
}

func (c *Types) Delete() error {
	return DB.Delete(c).Error
}
